package com.turing.merchant.commandLine;

import com.turing.merchant.mapper.MerchantCustomerMapper;
import com.turing.merchant.mapper.MerchantMapper;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Component
public class InitRedis implements CommandLineRunner {

    @Resource
    private MerchantMapper merchantMapper;
    @Resource
    private RedisTemplate redisTemplate;
    @Resource
    private MerchantCustomerMapper merchantCustomerMapper;

    @Override
    public void run(String... args) throws Exception {
        List<Map> list = merchantMapper.listMerComments();
        ZSetOperations valueOps = redisTemplate.opsForZSet();
        for (Map map : list) {
            valueOps.add("merchantComments", map.get("id"), (Long) map.get("counts"));
        }

//        List<Map> list1 = merchantCustomerMapper.listCusComments();
//        ZSetOperations valueOps1 = redisTemplate.opsForZSet();
//        for (Map map : list1) {
//            valueOps1.add("cusComments", map.get("id"), (Long) map.get("counts"));
//        }
    }
}
